// 查询列表
import request from "@/utils/request";

/**
 * 列表
 * @param data
 * @returns {AxiosPromise}
 */
export function listCate(data) {
    return request({
        url: '/wbzj-biz/projcate/getCatePageList',
        method: 'post',
        data: data
    })
}

// 获取选择框列表
export function getCateOptionselect() {
    let data={status:"1"};
    return request({
        url: '/wbzj-biz/projcate/getCateList',
        method: 'post',
        data: data
    })
}

/**
 * 修改
 * @param prdId
 * @returns {AxiosPromise}
 */
export function getCateByCode(code) {
    return request({
        url: '/wbzj-biz/projcate/getCate/'+code,
        method: 'get'
    })
}

// 保存
export function updateCate(data) {
    return request({
        url: '/wbzj-biz/projcate/saveCate',
        method: 'post',
        data: data
    })
}
export function insertCate(data) {
    return request({
        url: '/wbzj-biz/projcate/insertCate',
        method: 'post',
        data: data
    })
}

// 删除
export function delCateByCode(code) {
    return request({
        url: '/wbzj-biz/projcate/delCate/' + code,
        method: 'delete'
    })
}


/**
 * 获取服务类目项 树
 * @returns {AxiosPromise}
 */
export function TreeCate() {
    return request({
        url: '/wbzj-biz/projcate/getCate',
        method: 'get'
    })
}

export function cateOptionsSelect(){
    return TreeCate().then(response =>{
        let cateOptions =[];
        let res=response.data;
        for(let idx in res){
            let obj={value:res[idx].cateCode,label:res[idx].cateName,children:[]};
            let items=res[idx].items;
            for(let idx2 in items){
                let item=items[idx2]
                let sub={value:item.itemCode,label:item.itemName,img:item.itemImg}
                obj.children.push(sub);
            }
            cateOptions.push(obj)
        }
        return cateOptions;

    })
}

/**
 * 获取服务项目 树
 * @returns {AxiosPromise}
 */
export function TreeProj() {
    return request({
        url: '/wbzj-biz/projcate/getProjRelActiveTree',//'/wbzj-biz/projcate/getProjTree',
        method: 'get'
    })
}
export function projOptionsSelect(){
    return TreeProj().then(response =>{
        let projOptions =[];
        let res=response.data;
        for(let idx in res){
            let proj={value:res[idx].projCode,label:res[idx].projName,children:[]};
            let cates=res[idx].cates;
            for(let idx2 in cates){
                let cate=cates[idx2]
                let sub={value:cate.cateCode,label:cate.cateName,children:[]}

                let items=cate.items;
                for(let idx3 in items){
                    let item=items[idx3]
                    let thrid={value:item.itemCode,label:item.itemName
                        ,img:item.itemImg
                        ,price:item.projItemList[0]?item.projItemList[0].priceFloor:undefined}
                    sub.children.push(thrid);
                }

                proj.children.push(sub);
            }
            projOptions.push(proj)
        }
        return projOptions;

    })
}